package essentials;


import java.text.DecimalFormat;

public class ModelViewHelper {

    private SimpleGUI view;
    private Model model;

    public ModelViewHelper(SimpleGUI view, Model model) {
        this.view = view;
        this.model = model;
    }

    public String getTextFromGroesseTF() {
        return view.getGroesseTF().getText().trim();
    }

    public String getTextFromGewichtTF() {
        return view.getGewichtTF().getText().trim();
    }

    public String getTextFromInputTF() {
        return view.getInputTF().getText().trim();
    }

    public void setTextToGewichtTF(String textToGewichtTF) {
        view.getGewichtTF().setText(textToGewichtTF);
    }

    public void setTextToGroesseTF(String textToGroesseTF) {
        view.getGroesseTF().setText(textToGroesseTF);
    }

    public void setTextToInputTF(String textToInputTF) {
        view.getInputTF().setText(textToInputTF);
    }

    public void setTextToOutputTA(String textToOutputTA) {
        view.getOutputTA().setText(textToOutputTA);
    }

    public void setTextToBmiTF(String textToBmiTF) {
        view.getBmiTF().setText(textToBmiTF);
    }

    public void modelToView() {
        DecimalFormat decimalFormatter = UtilsToSort.getMySimpleDecimalFormatter();
        view.getOutputTA().setText(model.getFullInput());
        if (model.getGewicht() != null) {
            view.getGewichtTF().setText(decimalFormatter.format(model.getGewicht()));
        }
        if (model.getGroesse() != null) {
            view.getGroesseTF().setText(decimalFormatter.format(model.getGroesse()));
        }
        if (model.getBmi() != null) {
            view.getBmiTF().setText(model.getBmi().toString());
        } else {
            view.getBmiTF().setText("(null)");
        }
    }
    
    public void viewToModel() {
        
        model.setNewInput(view.getInputTF().getText());
        model.setGewicht(UtilsToSort.calcDoublefromString(getTextFromGewichtTF()));
        model.setGroesse(UtilsToSort.calcDoublefromString(getTextFromGroesseTF()));
    }    
}
